package com.wtwd.campus.receiver;


import com.wtwd.campus.common.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author ldaoliang
 * @Date create in 15:44 2021/3/25
 * @Description
 */
public class ReceiverFactory {

    private static final Logger logger = LoggerFactory.getLogger(ReceiverFactory.class);

    public static Receiver createReceiver(String data) {
        //解析消息类型判断创建哪一个处理器
        String[] split = data.split(",");
        String index = "";
        if (split.length <= 2) {//此处用于设备只上报了制造商名称和imei号的异常上报处理
            logger.info("未上报指令关键字的异常上报：" + data);
            return null;
        } else {
            index = split[2];
        }
        if (Constants.MESS_TYPE.equalsIgnoreCase(index)) {
            // V4消息处理器选择
            String type = split[3];
            if (Constants.ACTIVE_DEVICE_LOCATION.equals(type)) {   // 主动定位监控命令
                return new ActiveLocationReceiver();
            } else if (Constants.DEVICE_PARAMETERS.equals(type)) { //平台获取设备参数
                return new DeviceParametersReceiver();
            } else if (Constants.ICCID_AND_SIM.equals(type)) { //设备sim卡号和iccid上报
                return new DeviceSimAndIccidReceiver();
            } else if (Constants.SET_TEMPORARY_CONTROL_CENTER.equals(type)) {//设置临时监控中心
                return new SetTemporaryControlCenterReceiver();
            } else if (Constants.SET_DEFAULT_CONTROL_CENTER.equals(type)) {//设置默认控制中心
                return new SetDefaultControlCenterReceiver();
            } else if (Constants.SET_WORK_MODE.equals(type)) {//工作模式设置
                return new DeviceWorkModeReceiver();
            } else if (Constants.SET_UPLOAD_TIME.equals(type)) {//上报间隔设置
                return new DeviceUploadTimeReceiver();
            } else if (Constants.AUTO_CHANGE_WORK_MODE.equals(type)) {//闲置时间切换工作模式
                return new AutoChangeWorkModeReceiver();
            } else if (Constants.SET_MONITOR_NUMBER.equals(type)) {//监听号码设置指令
                return new MonitorNumberReceiver();
            } else if (Constants.SET_NO_DISTURB_TIME.equals(type)) {//设置免打扰时间协议
                return new SetNoDistrubTimeReceiver();
            } else if (Constants.SET_NO_DISTURB_SWITCH.equals(type)) {//设置免打扰时间开关
                return new SetNoDistrubSwitchReceiver();
            } else if (Constants.SET_NO_DISTURB_CONTROLLER.equals(type)) {//服务器设置使用课表或考勤标记控制设备的免打扰功能开关
                return new SetNoDisturbControllerReceiver();
            } else if (Constants.SET_SOS_DIAL_SWITCH.equals(type)) {//SOS电话拨号开关
                return new SetSOSDialSwitchReceiver();
            } else if (Constants.FACTORY_RESET.equals(type)) {//恢复出厂设置 S25
                return new FactoryResetReceiver();
            } else if (Constants.DEVICE_RESTART.equals(type)) {//重启指令R1
                return new DeviceRestartReceiver();
            } else if (Constants.VOLUME_ADJUSTMENT.equals(type)) {//喇叭音量调节
                return new VolumeAdjustmentReceiver();
            } else if (Constants.ALL_WHITELIST_NUMBER.equals(type)) {//一次性设置电话本白名单号码
                return new SetAllWhiteListNumberReceiver();
            } else if (Constants.WHITELIST_SWITCH.equals(type)) {//白名单功能开关
                return new SetWhiteListSwitchReceiver();
            } else if (Constants.WIRELESS_ATTENDANCE_SWITCH.equals(type)) {//无线考勤开关
                return new SetWirelessAttendanceSwitchReceiver();
            } else if (Constants.CIRCLE_POSITION_SETTING.equals(type)) {//圆形范围岗位/学校
                return new SetCirclePositionReceiver();
            } else if (Constants.POLYGON_POSITION_SETTING.equals(type)) {//多边形范围岗位/学校
                return new SetPolygonPositionReceiver();
            } else if (Constants.GET_DEVICE_STEP.equals(type)) {//平台主动获取计步数据
                return new ActiveGetStepReceiver();
            } else if (Constants.SINGLE_WHITELIST_NUMBER.equals(type)) { //单独设置电话本白名单回复
                return new SetSingleWhiteListNumberReceiver();
            } else if (Constants.ALL_SOS_PHONE.equals(type)) {//平台一次性设置sos号码
                return new setAllSosReceiver();
            } else if (Constants.WEATHER.equals(type)) {
                // TODO 天气指令会携带天气，为了避免漏掉，也解析
                return null;
            } else if (Constants.ALARM_CLOCK.equals(type)) {//设置闹钟的回复
                return new SetAlarmReceiver();
            } else if (Constants.DELETE_CLOCK.equals(type)) {//删除闹钟的回复
                return new DelAlarmReceiver();
            }
        } else if (Constants.LOCATE_HEART.equals(index)) {
            //V2消息,位置信息或者是定位后心跳数据发送
            return new UploadLocateHeartReceiver();
        } else if (Constants.NOT_LOCATE_HEART.equals(index)) {
            //未定位心跳数据发送
            return new UploadNotLocateHeartReceiver();
        } else if (Constants.SHUT_DOWN_WARNING.equals(index)) {
            //关机上报
            return new ShutDownReceiver();
        } else {
            //一般消息
            if (Constants.DEVICE_IMEID.equals(index)) {   // 获取设备机身码（IMEID）信息
                return new DeviceImeIdReceiver();
            } else if (Constants.SET_PDOP_THRESHOLD_VALUE.equals(index)) { //PDOP的门限值设定
                return new SetPDOPThresholdValueReceiver();
            } else if (Constants.CHANGE_DEVICE_ID.equals(index)) { //设备ID切换
                return new ChangeDeviceIdReceiver();
            } else if (Constants.SINGLE_WHITELIST_NUMBER.equals(index)) { //单独设置电话本白名单号码下发指令
                return new SetSingleWhiteListNumberReceiver();
            } else if (Constants.REPLY_ELECTRONIC_SING_IN.equals(index)) {//电子签到信息上报
                return new ElectronicSignInReceiver();
            } else if (Constants.REPLY_ELECTRONIC_SING_OUT.equals(index)) {//电子签退信息上报
                return new ElectronicSignOutReceiver();
            } else if (Constants.UPGRADE_DEVICE.equals(index)) { //FOTA升级（软件升级）
                return new UpgradeDeviceReceiver();
            } else if (Constants.UPGRADE_UPGRADE_STATUS.equals(index)) { //升级状态上报
                return new DeviceUpgradeStatusReceiver();
            } else if (Constants.SOS_WARNING.equals(index)) { //设备上传SOS报警协议格式
                return new UploadSOSWarningReceiver();
            } else if (Constants.LOW_BATTERY_WARNING.equals(index)) { //低电通知，当设备电量低于20%时
                return new UploadLowBatteryWarningReceiver();
            } else if (Constants.ACTIVE_UPLOAD_STEP.equals(index)) { //设备终端主动上报计步数据
                return new UploadStepReceiver();
            } else if (Constants.CALL_RECORDS.equals(index)) { //通话记录上报
                return new UploadCallRecordsReceiver();
            } else if (Constants.MONITOR_RECORDS.equals(index)) { //监听记录上报
                return new UploadMonitorRecordsReceiver();
            } else if (Constants.DEVICE_POWER_ON.equals(index)) { //设备开机主动上报开机指令
                return new UploadPowerOnDataReceiver();
            } else if (Constants.RESET_M1_CARD.equals(index)) { //M1卡变更
                return new ResetMCardReceiver();
            } else if (Constants.REMOVE_BINDING.equals(index)) { //清除绑定（改写绑定）
                return new RemoveBindingReceiver();
            } else if (Constants.WIFIMAC.equals(index)) {   // WIFIMAC上报
                return new WifiMacReceiver();
            }
            // 喜马拉雅 新增协议
            else if ("BINDINGSTATUS".equals(index)) {
                return new XMLYBindingStatus();
            } else if ("TEXTINFORM".equals(index)) {
                return new SendTextReceiver();
            }
            // 威科姆定制协议
            else if (Constants.VCOM_SHORT_MESSAGE.equals(index)) {
                return new VcomShortMessageReceiver();
            } else if (Constants.VCOM_NOTICE_MESSAGE.equals(index)) {
                return new VcomNoticeMessageReceiver();
            } else if (Constants.VCOM_NOT_DISTURB.equals(index)) {
                return new VcomNotDisturbReceiver();
            } else if (Constants.GET_LT_AUTH_KEY.equals(index)) {//获取联通的鉴权密匙
                return new GetLtAuthKeyReceiver();
            } else if (Constants.GET_PHONE.equals(index)) {//获取服务端手机号码
                return new GetPhoneReceiver();
            }
            //app上传信息类协议
            else if (Constants.UPLOAD_APP.equals(index)) {//设备内嵌app信息上报
                return new UploadAppReceiver();
            } else if (Constants.UPLOAD_APP_FILE.equals(index)) {
                return new UplocaAppFile();
            } else if (Constants.APP_INSTALLATION.equals(index)) {
                return new SetAppInstallationReceiver();
            } else if (Constants.APP_DISABLE.equals(index)) {
                return new SetAppDisableReceiver();
            }
            //锁卡锁机锁网执行组
            else if (Constants.LOCK_NET.equals(index)) {
                return new SetLockNetReceiver();
            } else if (Constants.LOCK_CARD.equals(index)) {
                return new SetLockCardReceiver();
            } else if (Constants.LOCK_DEVICE.equals(index)) {
                return new SetLockDeviceReceiver();
            } else if (Constants.GET_LOCK_NET.equals(index)) {
                return new GetLockNetReceiver();
            } else if (Constants.GET_LOCK_CARD.equals(index)) {
                return new GetLockCardReceiver();
            } else if (Constants.GET_LOCK_DEVICE.equals(index)) {
                return new GetLockDeviceReceiver();
            }
        }
        return null;
    }


}
